<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;

class SpikeResource extends JsonResource
{
    /**
     * 秒杀商品格式化
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'name'          => $this->name,
            'start_at'      => Carbon::parse($this->start_at)->timestamp,
            'end_at'        => Carbon::parse($this->end_at)->timestamp,
            'product'       => ProductListResource::collection($this->whenLoaded('productTakeThree'))
        ];
    }
}
